package pkg.drowne.org;

import java.util.ArrayList;
import android.graphics.drawable.Drawable;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

@SuppressWarnings("rawtypes")
public class OverlayManager extends ItemizedOverlay {

	// list of overlays
	private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
	
	public OverlayManager(Drawable defaultMarker) {
		super(boundCenter(defaultMarker));
		//super(defaultMarker);
	}

	@Override
	protected OverlayItem createItem(int i) {
		return mOverlays.get(i);
	}

	@Override
	public int size() {
		return mOverlays.size();
	}

	// method for add new overlays
	public void addOverlay(OverlayItem overlay) {
	    
		mOverlays.add(overlay);
		
	    // Each time you add a new OverlayItem to the ArrayList, 
    	// you must call populate() for the ItemizedOverlay, 
    	// which will read each of the OverlayItem
    	// When the populate() method executes, it will call createItem(int) 
    	// in the ItemizedOverlay to retrieve each OverlayItem. 

		populate();
	    
	}
	
	protected int getIndexToDraw(int drawingOrder){

	    return super.getIndexToDraw(drawingOrder);
	}
	
	public int removeOverlay(OverlayItem overlay) {
	    
	    mOverlays.remove(overlay);
	    //populate();
	    
	    return mOverlays.size();
	}
	
	@Override
	protected boolean onTap(int index) {
//	  OverlayItem item = mOverlays.get(index);
//	  AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
//	  dialog.setTitle(item.getTitle());
//	  dialog.setMessage(item.getSnippet());
//	  dialog.show();
	  return true;
	}
	
}
